
//1.更新传感器打钩的列表,调用子iframe中绘制曲线的方法重新绘制曲线
function paintSensorCurveLine(sensorno){
    //根据传感器编号获取该svg中绘制的曲线
    let leftsvgsensorno=$('#svgsensorno'+sensorno,document.getElementById('iframeMiddle').contentWindow.document);

    //获取子页面中的元素
    let leftsensorno=$('#sensorno'+sensorno,document.getElementById('iframeLeft').contentWindow.document);
    //使用jquery获取checkbox是否选中推荐使用的方式
    if(leftsensorno.prop('checked')) {
        //防止重复点击checkbox
        leftsensorno.attr("disabled",true);
        if(leftsvgsensorno.length>0){
            leftsvgsensorno.css('display','block');
        }else{
            //此处不能使用jquery,为了保证用户体验,此处要使用异步操作请求获取数据绘制曲线
            document.getElementById('iframeMiddle').contentWindow.paintSvgCurveLine(sensorno);
        }
        leftsensorno.attr("disabled",false);
    }else{
        $('#sensorno'+sensorno).prop("checked",false);
        //leftsvgsensorno.attr("points","");
        //将曲线隐藏,防止重新绘制出现的卡顿
        leftsvgsensorno.css('display','none');
        //移除曲线
        //leftsvgsensorno.remove();
    }
}
//2.查询选中的所有传感器
function getAllSelectSeneor(){
    let sensorArray = new Array();
    var domSenListLeft = $(".senListLeft",document.getElementById('iframeLeft').contentWindow.document);
    for(let j=0;j<domSenListLeft.find("li").length;j++){
        //获取li下的input下的checkbox
        let sensorIsChecked=domSenListLeft.find("li:eq("+j+")").find("input:first").is(':checked');
        if(sensorIsChecked){
            let sensorno=domSenListLeft.find("li:eq("+j+")").find("input:eq(1)").val();
            sensorArray.push(sensorno);
        }
    }
    return  sensorArray;
}

//3.根据曲线的移动实时显示传感器的值
function showSensorValues(xAxisValues){
    var domSenListLeft = $(".senListLeft",document.getElementById('iframeLeft').contentWindow.document);
    for(let j=0;j<domSenListLeft.find("li").length;j++){
        //获取li下的input下的checkbox
        let sensorIsChecked=domSenListLeft.find("li:eq("+j+")").find("input:first").is(':checked');
        if(sensorIsChecked){
            //获取选中传感器的传感器编号
            let sensorno=domSenListLeft.find("li:eq("+j+")").find("input:eq(1)").val();
            //当前鼠标停留的y轴值
            //根据x轴值获取y轴值
            //方案1:请求后台获取y轴值
            //let yAxisValue=document.getElementById('iframeMiddle').contentWindow.getYAxisValue(sensorno,xAxisValues);
            //方案2:从sessionStorage中获取
            let yAxisValue=document.getElementById('iframeMiddle').contentWindow.getYAxisValueFromSessionStorage(sensorno,xAxisValues);
            if(yAxisValue!=""){
                let value=domSenListLeft.find("li:eq("+j+")").find("label:eq(1)").text();
                let unit=getUnit(value);
                domSenListLeft.find("li:eq("+j+")").find("label:eq(1)").html(yAxisValue+" "+unit);
                //return yAxisValue+unit;
            }

        }
    }

}

//4.根据x轴坐标和传感器编号获取传感器的实时值
function getSensorValues(xAxisValues,sensorNo){
    //将所有传感器的值存放在数组中,并以json的方式保存在sessionStorage中
    var domSenListLeft = $(".senListLeft",document.getElementById('iframeLeft').contentWindow.document);
    for(let j=0;j<domSenListLeft.find("li").length;j++){
        //获取li下的input下的checkbox
        let sensorIsChecked=domSenListLeft.find("li:eq("+j+")").find("input:first").is(':checked');
        if(sensorIsChecked){
            //获取选中传感器的传感器编号
            let leftsensorno=domSenListLeft.find("li:eq("+j+")").find("input:eq(1)").val();
            if(leftsensorno==sensorNo){
                //从sessionStorage中获取y的值
                let yAxisValue=document.getElementById('iframeMiddle').contentWindow.getYAxisValueFromSessionStorage(leftsensorno,xAxisValues);
                if(yAxisValue!=""){
                    let value=domSenListLeft.find("li:eq("+j+")").find("label:eq(1)").text();
                    let unit=getUnit(value);
                    domSenListLeft.find("li:eq("+j+")").find("label:eq(1)").html(yAxisValue+unit);
                    return yAxisValue+unit;
                }
            }
        }
    }
}

//5.根据传感器编号获取该传感器的数据列表
function getSensorDataBySensorNo(sensorno) {
    let sensorValues="";
    //yyi 修改 现在使用labcode 跟primaryKey都是用写死的形式
    /*let labcode = "Haierrefrigerator20151214";
    let nowprimarykey="2017-11-1611:17:211";*/
   /* let labcode= $.cookie('labcode');
    let nowprimarykey= $.cookie('nowprimarykey');*/
   let labcode = "Haierrefrigerator20151214";
   let nowprimarykey = "2019-04-28 16:12:001";
    let topBasePath=getTopBasePath(top.basePath);
    //let sensorcolor= $.cookie(sensorno+'color');
    //let sensorcolor= sessionStorage.getItem(sensorno+'color');
    $.ajax({
        type: "get",
        //async: true,//设置为异步请求
        async: false,//设置为同步请求,防止接收不到数据
        /*url: topBasePath+config.bxxs.apiPath+"/TestData/getSensorTestDataNow",*/
        url: "http://localhost/consumer/CurveInfoAPI/getSensorTestDataNow",
        data:{
            labcode:labcode,
            primaryKey:nowprimarykey,
            sensorno:sensorno
        },
        success: function (msg) {
            if(msg.length>0){
                sensorValues=msg[0];
            }
        },
        error: function (e) {
            alert("网页发生错误：", e, "error");
        }
    });

    return sensorValues;
}

//6.抓取左侧所有传感器信息
function getLeftSensorData(){
    var leftSensorData = $("#sensorData",document.getElementById('iframeLeft').contentWindow.document);
    return leftSensorData.html();
}

//从SessionStorage中获取颜色信息
function getColorFromSessionStorage(storageColor){
    if(storageColor=="sensorColor color1"){
        return "#ff0000";
    }else if(storageColor=="sensorColor color2"){
        return "#5bff42";
    }else if(storageColor=="sensorColor color3"){
        return "#1534ff";
    }else if(storageColor=="sensorColor color4"){
        return "#fff43d";
    }else if(storageColor=="sensorColor color5"){
        return "#ff22d5";
    }else if(storageColor=="sensorColor color6"){
        return "#6e6aff";
    }else if(storageColor=="sensorColor color7"){
        return "#ff8850";
    }else if(storageColor=="sensorColor color8"){
        return "#2eb1ff";
    }else if(storageColor=="sensorColor color9"){
        return "#cfecff";
    }else if(storageColor=="sensorColor color10"){
        return "#fae7ff";
    }else if(storageColor=="sensorColor color11"){
        return "#2e3844";
    }else if(storageColor=="sensorColor color12"){
        return "#1f601e";
    }else if(storageColor=="sensorColor color13"){
        return "#9c5a4c";
    }else{
        return "#ff0000";
    }

}






